package com.sright.bcard.common.service.share.dto.page;

import com.sright.bcard.common.service.share.utils.DateTimeUtils;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.text.ParseException;
import java.util.Date;

/**
 * offset 分页请求参数dto类
 */
@Data
public class BetweenDateParamRequest implements Serializable {

    public static BetweenDateParamRequest request(Long beginStamp, Long endStamp) throws ParseException {
        if (beginStamp == null || endStamp == null) {
            return new BetweenDateParamRequest();
        }
        Date beginDate = null;
        Date endDate = null;
        if(beginStamp != null) {
            String stringDate = DateTimeUtils.longTransStringDate(beginStamp * 1000);
            beginDate = DateTimeUtils.formateTimeStart(stringDate);
        }
        if(endStamp != null) {
            String stringDate = DateTimeUtils.longTransStringDate(endStamp * 1000);
            endDate = DateTimeUtils.formateTimeStart(stringDate);
        }
        return BetweenDateParamRequest.request(beginDate, endDate);
    }

    public static BetweenDateParamRequest request(Date beginDate, Date endDate){
        BetweenDateParamRequest request = new BetweenDateParamRequest();
        request.setBeginDate(beginDate);
        request.setEndDate(endDate);
        return request;
    }


    @NotNull
    protected Date beginDate;

    /**
     * 获取的数量
     */
    @NotNull
    protected Date endDate;

    public Long beginTimeStamp() {
        return beginDate.getTime();
    }

    public Long endTimeStamp() {
        return endDate.getTime();
    }

}
